import { skuOriginalOptions } from '@/pages/commodity/modules/constants/skuInfoModule/skuOptionsList';
import { getListByReturnMapKey } from '@/utils/getUtils';
// 获取包装层数columns集合
const getPackageLayerList = () => {
  return [
    { label: '单品', value: 'single' },
    { label: '一层', value: 'one' },
  ].reduce((value, item) => {
    value.push(...[
      {
        title: `${item.label}包装单位`,
        key: `${item.value}PackageUnit`
      },
      {
        title: `${item.label}数量`,
        key: `${item.value}PackageCount`,
      },
      {
        title: `${item.label}最长边（cm）`,
        key: `${item.value}Edge1`,
      },
      {
        title: `${item.label}次长边（cm）`,
        key: `${item.value}Edge2`,
      },
      {
        title: `${item.label}最短边（cm）`,
        key: `${item.value}Edge3`,
      },
      {
        title: `${item.label}包装体积（m³）`,
        key: `${item.value}Volume`,
      },
      {
        title: `${item.label}重量（kg）`,
        key: `${item.value}Weight`,
      },
    ]);
    return value;
  }, []);
}
/**
 * @h h渲染
 * @list 要循环渲染的集合
 * @text el-popover要展示的文本内容
 * @title 悬浮弹框标题
 * @key 循环渲染的item文本key，如果没有就默认展示循环item
*/
const getElPopover = ({ h, list, text, title, key }) => {
  const ulStyle = `padding-left: 15px; max-height: 300px; overflow: hidden; overflow-y: auto;`
  const liStyle = `border-bottom: 1px dashed #ccc; margin-bottom: 10px;`;
  return <el-popover
    placement="right"
    width="300"
    trigger="hover">
    <el-card shadow="never">
      <div slot="header">{title}</div>
      <ul style={ulStyle}>{
        list.map(item => {
          return <li style={liStyle}>{key ? item[key] : item}</li>
        })
      }</ul>
    </el-card>
    <span slot="reference">{text}</span>
  </el-popover>
}
// 获取销售属性列的render
const getRenderBySaleAttrs = (h, row) => {
  const saleAttrInfoList = row?.saleAttrInfoList ?? []
  if (saleAttrInfoList.length == 0) return <span></span>
  return getElPopover({
    h,
    list: saleAttrInfoList,
    text: saleAttrInfoList.join(','),
    title: '销售属性'
  })
}
// 获取基本信息列的render
const getRenderByBasicInfo = (h, row) => {
  if (!row.notSpecAttrInfoList) { return <span>{row.notSpecAttrInfoNum}</span> }
  return getElPopover({
    h,
    list: row.notSpecAttrInfoList,
    text: row.notSpecAttrInfoNum,
    title: '基本信息'
  });
}
// 获取别名信息列的render
const getRenderByAliasName = (h, row) => {
  const aliasNames = getListByReturnMapKey(row.keywordInfoDTO?.aliasInfoList || [], 'aliasName');
  if (aliasNames.length === 0) { return <span></span>; }
  return getElPopover({
    h,
    list: row.keywordInfoDTO?.aliasInfoList,
    text: aliasNames.join(','),
    title: '别名',
    key: 'aliasName'
  });
}
export const goodsInfoColumns = [].concat([
  {
    title: '四级类名称',
    key: 'categoryName'
  },
  {
    title: '四级类代码',
    key: 'categoryNo'
  },
  {
    title: '是否敏感',
    key: 'isPriceSensitive'
  },
  {
    title: '是否金属制品',
    key: 'isMetal'
  },
  {
    title: 'SPU码',
    key: 'spuNo'
  },
  {
    title: 'SKU码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '销售属性',
    notShowTip: true,
    render: (h, { row }) => getRenderBySaleAttrs(h, row)
  },
  {
    title: '关键词',
    render: (h, { row }) => {
      return <span>{row.keywordInfoDTO?.keywordName || ''}</span>
    }
  },
  {
    title: '别名',
    render: (h, { row }) => {
      return getRenderByAliasName(h, row);
    }
  },
  {
    title: '基本信息',
    render: (h, { row }) => {
      return getRenderByBasicInfo(h, row);
    }
  },
  {
    title: '主计量单位',
    key: 'mainUnit'
  },
  {
    title: '数量小数位',
    key: 'mainDecimal'
  },
  {
    title: '商品类型',
    key: 'productType'
  },
  {
    title: '品牌',
    key: 'brandName'
  },
  {
    title: '系列',
    key: 'brandSeries'
  },
  {
    title: '经营模式',
    key: 'dealMode'
  },
  {
    title: '包装清单',
    key: 'packlist'
  },
  {
    title: '商品管理区域',
    key: 'manageArea'
  },
  {
    title: '合作模式',
    key: 'cooperation'
  },
  {
    title: '售价管理周期',
    key: 'sellManagePeriod'
  },
  {
    title: '档次外部定位',
    key: 'outpos'
  },
  {
    title: '档次内部定位',
    key: 'inpos'
  },
  {
    title: '是否季节性商品',
    key: 'seasonProduct'
  },
  {
    title: '囤货期',
    key: 'stockPeriod'
  },
  {
    title: '下架期',
    key: 'soldoutPeriod'
  },
  {
    title: '售卖平台',
    key: 'saleplat'
  },
  {
    title: '归类名称',
    key: 'classificationName'
  },
  {
    title: '税率',
    key: 'taxRate'
  },
  {
    title: '最小起售量（销售）',
    key: 'saleMin'
  },
  {
    title: '销售限制类型（销售）',
    key: 'saleRestrict'
  },
  {
    title: '安全率（下限 - 上限）',
    key: 'safetyRate'
  },
  {
    title: '件装数量',
    key: 'pieceInfo'
  },
  {
    title: '商品条形码',
    key: 'barcode'
  },
  {
    title: '商品信息备注',
    key: 'skuRemark',
  },
  {
    title: '产地',
    key: 'producingAreaName'
  },
  {
    title: 'Sku来源',
    render: (h, { row }) => {
      let result = skuOriginalOptions.find(item => {
        return item.value === row.skuSource;
      })
      return (
        <div>{ result ? result.label : '' }</div>
      )
    }
  },
  {
    title: '来源详情',
    key: 'skuSourceDesc',
  },
  {
    title: '副标题',
    key: 'subtitle'
  },
  {
    title: '包装层数',
    key: 'packageLayers'
  },
], getPackageLayerList());
// 进价信息
export const purchasePriceInfoColumns = [
  {
    title: '供应商代码',
    key: 'supplierCode'
  },
  {
    title: '供应商名称',
    key: 'supplierName'
  },
  {
    title: 'SPU码',
    key: 'spuNo'
  },
  {
    title: 'SKU码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '销售属性',
    key: 'specDetailStr'
  },
  {
    title: '主计量单位',
    key: 'mainUnit'
  },
  {
    title: '进价类型',
    key: 'purchasePriceType'
  },
  {
    title: '销售区域',
    key: 'saleArea'
  },
  {
    title: '省',
    key: 'saleProvince'
  },
  {
    title: '城市（省会）',
    key: 'saleProvinceCenter'
  },
  {
    title: '是否供货',
    key: 'isSupply'
  },
  {
    title: '参照城市',
    key: 'templateCity'
  },
  {
    title: '进价参照比例',
    key: 'purPriceTemplateRatio'
  },
  {
    title: '成本参照比例',
    key: 'costPriceTemplateRatio'
  },
  {
    title: '主计量进价',
    key: 'mainPurchasePrice'
  },
  {
    title: '进价备注',
    key: 'purchasePriceNote'
  },
  {
    title: '厂家代码',
    key: 'factoryCode'
  },
  {
    title: '厂家名称',
    key: 'factoryName'
  },
  {
    title: '厂家面价',
    key: 'factoryFacePrice'
  },
  {
    title: '加价类型',
    key: 'addPriceType'
  },
  {
    title: '运费折合比例',
    key: 'freightRatio'
  },
  {
    title: '包装费折合比例',
    key: 'packRatio'
  },
  {
    title: '加工费折合比例',
    minWidth: 200,
    key: 'processChargesRatio'
  },
  {
    title: '返利折合比例',
    minWidth: 200,
    key: 'rebateRatio'
  },
  /* {
    title: '返利说明',
    key: 'rebateRatioDesc',
  }, */
  {
    title: '成本价',
    minWidth: 200,
    key: 'mainUnitCostPrice'
  },
]
// 进价信息多计量
export const purchasePriceSteelInfoColumns = [
  {
    title: '供应商代码',
    key: 'supplierCode'
  },
  {
    title: '供应商名称',
    key: 'supplierName'
  },
  {
    title: 'SPU码',
    key: 'spuNo'
  },
  {
    title: 'SKU码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '销售属性',
    key: 'specDetailStr'
  },
  {
    title: '主计量单位',
    key: 'mainUnit'
  },
  {
    title: '辅计量单位',
    key: 'supplyGoodsUnit'
  },
  {
    title: '进价类型',
    key: 'purchasePriceType'
  },
  {
    title: '销售区域',
    key: 'saleArea'
  },
  {
    title: '省',
    key: 'saleProvince'
  },
  {
    title: '城市',
    key: 'saleProvinceCenter'
  },
  {
    title: '参照城市',
    key: 'templateCity'
  },
  {
    title: '进价参照比例',
    key: 'purPriceTemplateRatio'
  },
  {
    title: '成本参照比例',
    key: 'costPriceTemplateRatio'
  },
  {
    title: '理论转换率',
    key: 'theoryConvertRatio'
  },
  {
    title: '实际转换率',
    key: 'actualConvertRatio'
  },
  {
    title: '辅计量进价',
    key: 'purchasePrice'
  },
  {
    title: '主计量进价',
    key: 'mainPurchasePrice'
  },
  {
    title: '进价备注',
    key: 'purchasePriceNote'
  },
  {
    title: '厂家代码',
    key: 'factoryCode'
  },
  {
    title: '厂家名称',
    key: 'factoryName'
  },
  {
    title: '加价类型',
    key: 'addPriceType'
  },
  {
    title: '运费折合比例',
    key: 'freightRatio'
  },
  {
    title: '包装费折合比例',
    key: 'packRatio'
  },
  {
    title: '加工费折合比例',
    minWidth: 200,
    key: 'processChargesRatio'
  },
  {
    title: '返利折合比例',
    minWidth: 200,
    key: 'rebateRatio'
  },
  /* {
    title: '返利说明',
    key: 'rebateRatioDesc',
  }, */
  {
    title: '实际转换率辅计量成本价',
    minWidth: 200,
    key: 'actualConvertRatioCostPrice'
  },
  {
    title: '理论转换率辅计量成本价',
    minWidth: 200,
    key: 'theoryConvertRatioCostPrice'
  },
  {
    title: '主计量成本价',
    minWidth: 200,
    key: 'mainUnitCostPrice'
  },
]

// 售价信息
export const saleInfoColumns = [
  {
    title: 'SPU码',
    key: 'spuNo'
  },
  {
    title: 'SKU码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '销售属性',
    key: 'specDetailStr'
  },
  {
    title: '主计量单位',
    key: 'mainUnit'
  },
  {
    title: '售价类型',
    key: 'saleType'
  },
  {
    title: '省',
    key: 'saleProvince'
  },
  {
    title: '城市',
    key: 'saleProvinceCenter'
  },
  {
    title: '销售区域简称',
    key: 'saleAreaShotName'
  },
  {
    title: '价格组',
    key: 'priceGroup'
  },
  {
    title: '主城市',
    key: 'mainCity'
  },
  {
    title: '业务区域',
    key: 'saleArea'
  },
  {
    title: '参照价格组',
    key: 'templatePriceGroup'
  },
  {
    title: '参照售价比例',
    key: 'templateSalePriceRatio'
  },
  {
    title: '成本价',
    key: 'costPrice'
  },
  {
    title: '加价类型',
    key: 'addPriceType'
  },
  {
    title: '销售面价',
    key: 'facePrice2'
  },
  {
    title: '现金价标准加价率',
    key: 'cashPriceAddRate'
  },
  {
    title: '现金价（元）',
    key: 'cashPrice'
  },
  {
    title: '现金实时加价率',
    key: 'realCashPriceAddRate'
  },
  {
    title: '费用利润比',
    key: 'profit'
  },
  {
    title: '分销与现金差额/差率',
    key: 'distribCashDiffRateOrMoney'
  },
  {
    title: '分销价',
    key: 'cashDistribMoney'
  },
  {
    title: '分销实时加价率',
    key: 'realDistribPriceAddRate'
  },
  {
    title: '售价',
    key: 'salePrice'
  },
  {
    title: '售价标准加价率',
    key: 'saleAddRateOrMoney'
  },
  {
    title: '售价实际加价率',
    key: 'realSalePriceAddRate'
  },
  {
    title: '限制展示价',
    key: 'limitShowPrice'
  },
  {
    title: '限制交易价',
    key: 'limitTradePrice'
  },
]
// 售价多计量
export const saleSteelInfoColumns = [
  {
    title: 'SPU码',
    key: 'spuNo'
  },
  {
    title: 'SKU码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '销售属性',
    key: 'specDetailStr'
  },
  {
    title: '主计量单位',
    key: 'mainUnit'
  },
  {
    title: '辅计量单位',
    key: 'supplyGoodsUnit'
  },
  {
    title: '售价类型',
    key: 'saleType'
  },
  {
    title: '销售区域简称',
    key: 'saleAreaShotName'
  },
  {
    title: '省',
    key: 'saleProvince'
  },
  {
    title: '城市',
    key: 'saleProvinceCenter'
  },
  {
    title: '价格组',
    key: 'priceGroup'
  },
  {
    title: '主城市',
    key: 'mainCity'
  },
  {
    title: '业务区域',
    key: 'saleArea'
  },
  {
    title: '参照价格组',
    key: 'templatePriceGroup'
  },
  {
    title: '参照售价比例',
    key: 'templateSalePriceRatio'
  },
  {
    title: '理论转换率',
    key: 'theoryConvertRatio'
  },
  {
    title: '实际转换率',
    key: 'actualConvertRatio'
  },
  {
    title: '实际转换率辅成本价',
    key: 'actualConvertRatioCostPrice'
  },
  {
    title: '理论转换率辅成本价',
    key: 'theoryConvertRatioCostPrice'
  },
  {
    title: '主成本价',
    // key: 'mainUnitCostPrice'
    key: 'costPrice'
  },
  {
    title: '加价类型',
    key: 'addPriceType'
  },
  {
    title: '销售面价',
    key: 'facePrice2'
  },
  {
    title: '现金价',
    key: 'cashPrice'
  },
  {
    title: '现金价标准加价率/金额',
    key: 'cashPriceAddRate'
  },
  {
    title: '辅分销价',
    key: 'backUnitDistribPrice'
  },
  {
    title: '分销价',
    key: 'cashDistribMoney'
  },
  {
    title: '分销实时加价率',
    key: 'realDistribPriceAddRate'
  },
  {
    title: '辅售价',
    key: 'backUnitSalePrice'
  },
  {
    title: '售价',
    key: 'salePrice'
  },
  {
    title: '售价标准加价率',
    key: 'saleAddRateOrMoney'
  },
  {
    title: '售价实际加价率',
    key: 'realSalePriceAddRate'
  },
  {
    title: '现金辅计量批量加价金额/比例',
    key: 'cashBackUnitAddRateOrMoney'
  },
  {
    title: '现金辅计量批量价',
    key: 'cashBackUnitBatchPrice'
  },
  {
    title: '辅计量批量售价加价金额/比例',
    key: 'saleBackUnitAddRateOrMoney'
  },
  {
    title: '售价辅计量批量价',
    key: 'saleBackUnitBatchPrice'
  },
  {
    title: '限制展示价',
    key: 'limitShowPrice'
  },
  {
    title: '限制交易价',
    key: 'limitTradePrice'
  },
]

// 验收标准
export const acceptStandardInfoColumns = [
  {
    title: '分类',
    key: 'categoryName'
  },
  {
    title: 'SPU编码',
    key: 'spuNo'
  },
  {
    title: 'SKU编码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '品牌',
    key: 'brandName'
  },
  {
    title: '规格',
    key: 'specDetailStr'
  },
  {
    title: '验收频率',
    key: 'checkFrequency'
  },
  {
    title: '验收时间',
    key: 'checkTime'
  },
]
export const qualificationColumns = [
  {
    title: '分类',
    key: 'categoryPath'
  },
  {
    title: 'SPU编码',
    key: 'spuNo'
  },
  {
    title: 'SKU编码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '规格',
    key: 'specDetail'
  },
  {
    title: '资质类型',
    key: 'quaTypeStr'
  },
  {
    title: '供应商名称',
    key: 'supplierName'
  },
]

export { VIEW_RECORD_TABLE_COLUMNS as NEW_SALE_TABLE_COLUMNS } from '@/constants/salePrice';

export const IMAGE_TEXT_COLUMNS = [
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: 'SPU编码',
    key: 'spuNo'
  }
]

// Tab页签名称
export const NATIVE_NAMES = {
  ProductInfo: '1', // 商品信息
  PurchaseInfo: '2', // 进价信息（单计量）
  PurchaseInfoMulti: '3', // 进价信息（多计量）
  SaleInfo: '4', // 售价信息（单计量）
  SaleInfoMulti: '5', // 售价信息（多计量）
  AcceptanceStandard: '6', // 验收标准
  QualificationType: '7', // 资质类型
  ImageTextInfo: '8', // 图文信息
  SaleInfoNew: '9', // 售价信息（新）
}

// Tab页签列表
export const NATIVE_TABS_LIST = [
  {
    label: '商品信息',
    name: NATIVE_NAMES.ProductInfo
  },
  {
    label: '进价信息',
    name: NATIVE_NAMES.PurchaseInfo
  },
  {
    label: '进价信息(多计量)',
    name: NATIVE_NAMES.PurchaseInfoMulti
  },
  {
    label: '售价信息（新）',
    name: NATIVE_NAMES.SaleInfoNew
  },
  {
    label: '售价信息（旧）',
    name: NATIVE_NAMES.SaleInfo
  },
  {
    label: '售价信息(多计量)',
    name: NATIVE_NAMES.SaleInfoMulti
  },
  {
    label: '验收标准',
    name: NATIVE_NAMES.AcceptanceStandard
  },
  {
    label: '资质类型',
    name: NATIVE_NAMES.QualificationType
  },
  {
    label: '图文信息',
    name: NATIVE_NAMES.ImageTextInfo
  }
]
